#include "touchcontextmenu.h"
#include <QtGui>
#include "wndmanager.h"

//------------------------------------------------------------------------------
// PUBLIC INTERFACES
//------------------------------------------------------------------------------

TouchContextMenu::TouchContextMenu(const QStringList& menuItems, 
								   QWidget *parent)
	: QDialog(parent)
{
	menu = new QTableWidget(menuItems.size(), 1, this);
	menu->verticalHeader()->setVisible(false);
	menu->horizontalHeader()->setVisible(false);
	for(int menu_index = 0; menu_index < menuItems.size(); ++menu_index){
		QTableWidgetItem *widgetItem = 
					new QTableWidgetItem(menuItems.at(menu_index));
		widgetItem->setTextAlignment(Qt::AlignCenter);
		menu->setItem(menu_index, 0, widgetItem);
	}
	menu->setFixedSize(size());
	menu->setColumnWidth(0, width()-5);
	for(int r = 0; r < menu->rowCount(); ++r){
		menu->setRowHeight(r, (height()-5)/menu->rowCount());
	}

	connect(menu, SIGNAL(cellClicked(int, int)), this, SLOT(menuSelected(int, int)));

	WndManager::AdjustWndStyle(this);
}

TouchContextMenu::~TouchContextMenu()
{
	delete menu;
}

QString TouchContextMenu::getSelectedItem() const
{
	return selectedItem;
}

//------------------------------------------------------------------------------
// SLOTS
//------------------------------------------------------------------------------

void TouchContextMenu::menuSelected(int r, int c)
{
	selectedItem = menu->item(r, c)->text();
	accept();
}
